import "package:flutter/material.dart";
import "./RecommendItemContent.dart";
import "RecommendItemUPInfo.dart";

// 直播类型推荐的直播类
class RecommendItemLiveItem {
  String coverUrl; //封面图
  String viewCount; //浏览量
  String title; //标题
  bool isPromotion; //是否推广
  String? partition; //分区
  RecommendItemLiveItem({
    required this.coverUrl,
    required this.viewCount,
    required this.title,
    this.isPromotion = false,
    this.partition,
  });
}

// 直播类型推荐的直播类
class RecommendItemLiveItemWidget extends StatelessWidget {
  final RecommendItemLiveItem recommendItemLiveItem;
  final RecommendItemUPInfo? recommendItemUPInfo;
  const RecommendItemLiveItemWidget({
    super.key,
    required this.recommendItemLiveItem,
    this.recommendItemUPInfo,
  });
  @override
  Widget build(BuildContext context) {
    TextStyle textStyle = const TextStyle(
      fontSize: 10,
      color: Colors.white,
    );
    return RecommendItemContentWidget(
      imageUrl: recommendItemLiveItem.coverUrl,
      title: recommendItemLiveItem.title,
      titleMaxLine: 1,
      imageBottomBar: Padding(
        padding: const EdgeInsets.fromLTRB(5, 4, 5, 2),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Expanded(
              flex: 1,
              child: Row(
                children: [
                  const Icon(
                    Icons.remove_red_eye_outlined,
                    size: 12,
                    color: Colors.white,
                  ),
                  Padding(
                    padding: const EdgeInsets.only(left: 3),
                    child: Text(
                      recommendItemLiveItem.viewCount,
                      style: textStyle,
                    ),
                  ),
                ],
              ),
            ),
            recommendItemLiveItem.partition != null
                ? Text(
                    recommendItemLiveItem.partition ?? '',
                    style: textStyle,
                  )
                : Row(
                    children: [
                     const Icon(
                        Icons.bar_chart,
                        size: 12,
                        color: Colors.white,
                      ),
                      Text(
                        '直播',
                        style: textStyle,
                      )
                    ],
                  ),
          ],
        ),
      ),
      footer: recommendItemLiveItem.isPromotion
          ? Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                CircleAvatar(
                  radius: 16,
                  backgroundImage:
                      AssetImage(recommendItemUPInfo?.avatar ?? ''),
                  backgroundColor: Colors.black38,
                ),
                Expanded(
                  child: Padding(
                    padding: const EdgeInsets.only(left: 6),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          recommendItemUPInfo?.name ?? '',
                          style: const TextStyle(
                            fontSize: 13,
                            color: Colors.black87,
                          ),
                        ),
                        Row(
                          children: [
                            Icon(
                              Icons.rocket_launch,
                              size: 17,
                              color: Colors.pink.shade100,
                            ),
                            Container(
                              margin: const EdgeInsets.only(left: 2),
                              padding: const EdgeInsets.fromLTRB(2, 2, 2, 2),
                              decoration: BoxDecoration(
                                color: const Color.fromARGB(255, 255, 106, 156),
                                borderRadius: BorderRadius.circular(2),
                              ),
                              child: const Row(
                                children: [
                                  Icon(
                                    Icons.bar_chart,
                                    size: 14,
                                    color: Colors.white,
                                  ),
                                  Text(
                                    '直播中',
                                    maxLines: 1,
                                    overflow: TextOverflow.clip,
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontSize: 10,
                                    ),
                                  ),
                                ],
                              ),
                            )
                          ],
                        )
                      ],
                    ),
                  ),
                ),
              ],
            )
          : Row(
              children: [
                recommendItemUPInfo?.isSubscribed ?? false
                    ? const Row(
                        children: [
                          Icon(
                            Icons.check_circle_rounded,
                            color: Color.fromARGB(255, 255, 98, 0),
                            size: 14,
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 2),
                            child: Text(
                              '已关注',
                              style: TextStyle(
                                color: Color.fromARGB(255, 255, 98, 0),
                                fontSize: 12,
                              ),
                            ),
                          ),
                        ],
                      )
                    : const SizedBox(),
                Expanded(
                  flex: 1,
                  child: Padding(
                    padding: const EdgeInsets.only(left: 4),
                    child: Text(
                      recommendItemUPInfo?.name ?? '',
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: const TextStyle(
                        color: Colors.black54,
                        fontSize: 12,
                      ),
                    ),
                  ),
                )
              ],
            ),
    );
  }
}
